package com.pictureBook.merchant.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.pictureBook.merchant.entity.PictureBook;
import com.pictureBook.merchant.mapper.PictureBookMapper;
import com.pictureBook.merchant.service.IPictureBookService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.*;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author Ding
 * @since 2022-01-06
 */
@Service
public class PictureBookServiceImpl extends ServiceImpl<PictureBookMapper, PictureBook> implements IPictureBookService {

    @Resource
    private PictureBookMapper pictureBookMapper;

    @Override
    public PageInfo<Map<String, Object>> getAllPictureBooks(Integer soId, Integer index, Integer num, Map<String, Object> searchData) {
        PageHelper.startPage(index,num);
        return new PageInfo<>((List<Map<String,Object>>) pictureBookMapper.getAllPictureBooks(soId,searchData));
    }

    @Override
    public Map<String, Object> getPictureBookByAnISBN(String ISBN,Integer soId) {
        return pictureBookMapper.getPictureBookByAnISBN(ISBN,soId);
    }

    @Override
    public Map<String, Object> getPictureBookMainByAnISBN(String ISBN) {
        return pictureBookMapper.getPictureBookMainByAnISBN(ISBN);
    }

    @Override
    public int upDateBookNumAddOneById(Integer pb_id,Integer changeNum) {
        return pictureBookMapper.upDateBookNumAddOneById(pb_id,changeNum);
    }

    @Override
    public int toAddPictureBook(PictureBook pictureBookBean) {
        return pictureBookMapper.insert(pictureBookBean);
    }

    @Override
    public Integer getLastId() {
        return pictureBookMapper.getLastId();
    }

    @Override
    public PageInfo<Map<String,Object>> getPictureBookMainByBookName(Integer index,Integer num,String pbName) {
        PageHelper.startPage(index,num);
        return new PageInfo<>(pictureBookMapper.getPictureBookMainByBookName(pbName));
    }

    @Override
    public int delBooks(List<Integer> ids) {
        QueryWrapper<PictureBook> wrapper = new QueryWrapper<>();
        wrapper.in("pb_id",ids);
        return pictureBookMapper.delete(wrapper);
    }

    @Override
    public int editBook(PictureBook pictureBook) {
        UpdateWrapper<PictureBook> wrapper = new UpdateWrapper<>();
        wrapper.eq("pb_id",pictureBook.getPbId());
        return pictureBookMapper.update(pictureBook,wrapper);
    }

    @Override
    public Map<String, Object> getPictureBookById(Integer pbId) {
        return pictureBookMapper.getPictureBookById(pbId);
    }
}
